package com.umbrella.manage.utils;

//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;

//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.umbrella.ResultCode;
//import com.umbrella.exception.UmbraException;

public class XCXTokenTool {
	
//	private final static Logger LOG = LoggerFactory.getLogger(XCXTokenTool.class);
	//获取token的地址
	public static final String WEBCHAT_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential";
	public static final String XCX_APPID = "wxd846edc190effd46";	
	public static final String XCX_SECRET = "dc4f3234485fe38d9c039791f8b619f4";	
	
	/***************************小程序获取token，临时方法***************************/
	static String xcxaccessToken=null;
	static long lastRequestxcxWxTokenTime=0;
	private final static Object xcxaccessTokenLock = new Object();
	//临时方法
	public static String getTempXCXAccessToken() {
		synchronized (xcxaccessTokenLock) {
//			if(xcxaccessToken==null || System.currentTimeMillis()-lastRequestxcxWxTokenTime>100*60000){
//				xcxaccessToken=getXCXAccessTokenTemp();
//				lastRequestxcxWxTokenTime=System.currentTimeMillis();
//				LOG.info("--get webchat token from web:"+xcxaccessToken);
//			}
			return xcxaccessToken;
		}
	}
	
	private static String getXCXAccessTokenTemp(){
//		String url = WEBCHAT_TOKEN_URL + "&appid=" + XCX_APPID + "&secret=" + XCX_SECRET;
//		String result = HttpClientService.doGet(url.toString());
//		try {
//			
//			JSONObject jsonResult = JSON.parseObject(result);
//			
//			if(jsonResult!= null){
//				return jsonResult.getString("access_token");
//			}
//		} catch (Exception e) {
//			LOG.error("Cannot get xcx token", e);
//			throw new UmbraException(ResultCode.FAILED, "授权access_token获取失败");
//		}
		return null;
	}
}
